/**
 * Carnegie Mellon University
 * School of Computer Science
 * MSIT eBusiness Technology
 * 
 * Team 8 - Infinity (2011 Spring)
 * infinity-team8@googlegroups.com
 * 
 * Professor: Jeffrey L. Eppinger
 * Program Faculty: Sujata Telang
 */

package formbean;

import java.util.ArrayList;
import java.util.List;

import org.mybeans.form.FormBean;

public class EmployeeCreateEmployeeAccountForm extends FormBean {
	private String firstName;
	private String lastName;
	private String userName;
	private String password;
	private String confirm;
	
	public String getFirstName() { return firstName; }
	public String getLastName()  { return lastName;  }
	public String getUserName()  { return userName;  }
	public String getPassword()  { return password;  }
	public String getConfirm()   { return confirm;   }
	
	public void setFirstName(String s) { firstName = s.trim();  }
	public void setLastName(String s)  { lastName  = s.trim();  }
	public void setUserName(String s)  { userName  = s.trim();  }
	public void setPassword(String s)  { password  = s.trim();  }
	public void setConfirm(String s)   { confirm   = s.trim();  }

	public List<String> getValidationErrors() {
		List<String> errors = new ArrayList<String>();

		if (userName == null || userName.length() == 0) {
			errors.add("User Name is required");
		}
		
		if (userName.matches(".*[<>\"].*")) {
			errors.add("User Name may not contain angle brackets or quotes");
		}

		if (password == null || password.length() == 0) {
			errors.add("Password is required");
		}

		if (confirm == null || confirm.length() == 0) {
			errors.add("Confirm Password is required");
		}
		
		if (firstName == null || firstName.length() == 0) {
			errors.add("First Name is required");
		}
		
		if (firstName.matches(".*[<>\"].*")) {
			errors.add("First Name may not contain angle brackets or quotes");
		}
		
		if (firstName.matches(".*[^a-zA-Z].*")) {
			errors.add("First Name may only contain letters");
		}

		if (lastName == null || lastName.length() == 0) {
			errors.add("Last Name is required");
		}
		
		if (lastName.matches(".*[<>\"].*")) {
			errors.add("Last Name may not contain angle brackets or quotes");
		}
		
		if (lastName.matches(".*[^a-zA-Z].*")) {
			errors.add("Last Name may only contain letters");
		}

		
		
		if (errors.size() > 0) {
			return errors;
		}
		
		if (!password.equals(confirm)) {
			errors.add("Passwords are not the same");
		}
		
		return errors;
	}
}
